﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Ensures
{
    public static class Ensure
    {
		class EnsuresStatusTransaction : IEnsuresServiceTransaction
		{
			List<string> messages = new List<string>();
			public string[] FailMessages { get { return messages.ToArray(); } }
			public void Fail(string message)
			{
				IsFailed = true;
				messages.Add(message);
			}

			public bool IsFailed { get; private set; }
		}
		public static void That<T>(T obj, params Rule<T>[] rules)
		{
			EnsuresStatusTransaction transation = new EnsuresStatusTransaction();
			Array.ForEach(rules, r => r(obj, transation));
		}
    }
    public interface IEnsuresServiceTransaction
    {
        void Fail(string message);
        bool IsFailed { get; }
		string[] FailMessages { get; }
    }
	public delegate void Rule<T>(T obj, IEnsuresServiceTransaction transaction);
}
